package com.hertz.iris.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

public class Utils {
	
//	private static Properties properties = new Properties();
//	static{
//		InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("iris.properties");
//		try {
//			properties.load(inputStream);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
//
//	public static String getValues(String name){
//		return properties.getProperty(name);
//	}
	
	public static String byteWeekValues2String(byte[] weekValues){
		StringBuffer sb = new StringBuffer();
		for(byte v : weekValues){
			sb.append(v).append(",");
		}
		sb.substring(0, sb.length() - 1);
		return sb.toString();
	}
	
	public static byte[] string2byteArr(String str,String split){
		if(Strings.isBlank(str)){
			return null;
		}
		String[] arr = str.split(split);
		byte[] result = new byte[arr.length];
		for(byte i = 0; i < arr.length; i++){
			result[i] = Byte.valueOf(arr[i]);
		}
		return result;
	}
	
	public static int indexInArr(int[] arrs,int value){
		for(int i = 0; i < arrs.length; i++){
			if(value == arrs[i]){
				return i;
			}
		}
		return -1;
	}
	
	public static boolean checkNetwork(Context context) {
		// 获得网络连接服务
		ConnectivityManager connManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		// State state = connManager.getActiveNetworkInfo().getState();
		// 获取WIFI网络连接状态
		State wifiSstate = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
		// 判断是否正在使用WIFI网络

		// 获取GPRS网络连接状态
		State mobileSstate = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
		// 判断是否正在使用GPRS网络

		if (wifiSstate == State.CONNECTED || mobileSstate == State.CONNECTED) {
			return true;
		} else {
			return false;
		}
	}
	
}
